package com.augurit.common.syslog.convert;

import java.util.ArrayList;
import java.util.List;

import com.augurit.common.entity.SysTraceLog;
import com.augurit.common.syslog.web.form.SysTraceLogForm;

public class SysTraceLogConvertor {
	public static SysTraceLogForm convertVoToForm(SysTraceLog entity, boolean convertClobProp) {
		if(entity != null) {
			SysTraceLogForm form = new SysTraceLogForm();
			form.setId(entity.getId());
			form.setUserName(entity.getUserName());
			form.setLoggerName(entity.getLoggerName());
			form.setLogTime(entity.getLogTime());
			form.setLogLevel(entity.getLogLevel());
			form.setMessage(entity.getMessage());
			form.setThreadName(entity.getThreadName());
			form.setSuggestion(entity.getSuggestion());
			
			if(convertClobProp)
				form.setException(entity.getException());
			
			return form;
		}else
			return null;
	}
	
	public static void convertFormToVo(SysTraceLogForm form, SysTraceLog entity) {
		if(entity != null && form != null) {
			entity.setId(form.getId());
			if(form.getUserName() != null && form.getUserName().trim().length() > 0)
				entity.setUserName(form.getUserName().trim());
			if(form.getLoggerName() != null && form.getLoggerName().trim().length() > 0)
				entity.setLoggerName(form.getLoggerName().trim());
			entity.setLogTime(form.getLogTime());
			if(form.getLogLevel() != null && form.getLogLevel().trim().length() > 0)
				entity.setLogLevel(form.getLogLevel().trim());
			if(form.getMessage() != null && form.getMessage().trim().length() > 0)
				entity.setMessage(form.getMessage().trim());
			if(form.getThreadName() != null && form.getThreadName().trim().length() > 0)
				entity.setThreadName(form.getThreadName().trim());
			if(form.getSuggestion() != null && form.getSuggestion().trim().length() > 0)
				entity.setSuggestion(form.getSuggestion().trim());
			if(form.getException() != null)
				entity.setException(form.getException());
		}
	}
	
	public static List<SysTraceLogForm> convertVoListToFormList(List<SysTraceLog> sysTraceLogList) {
		if(sysTraceLogList != null && sysTraceLogList.size() > 0) {
			List<SysTraceLogForm> sysTraceLogFormList = new ArrayList();
			for(int i=0; i<sysTraceLogList.size(); i++) {
				sysTraceLogFormList.add(convertVoToForm(sysTraceLogList.get(i), false));
			}
			return sysTraceLogFormList;
		}
		return null;
	}
	
	public static List<SysTraceLog> convertFormListToVoList(List<SysTraceLogForm> sysTraceLogFormList) {
		if(sysTraceLogFormList != null && sysTraceLogFormList.size() > 0) {
			List<SysTraceLog> sysTraceLogList = new ArrayList();
			for(int i=0; i<sysTraceLogFormList.size(); i++) {
				SysTraceLog sysTraceLog = new SysTraceLog();
				convertFormToVo(sysTraceLogFormList.get(i), sysTraceLog);
				sysTraceLogList.add(sysTraceLog);
			}
			return sysTraceLogList;
		}
		return null;
	}
}